//
//  OTAShowView.m
//  project
//
//  Created by 黄建华 on 2018/3/27.
//  Copyright © 2018年 黄建华. All rights reserved.
//

#import "OTAShowView.h"

@implementation OTAShowView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.layer.cornerRadius = 6.0;
        self.layer.masksToBounds = YES;
        self.backgroundColor = [UIColor whiteColor];
    }
    
    return self;
}

- (void)showView1
{
    UIActivityIndicatorView *active = [[UIActivityIndicatorView alloc ]initWithFrame:CGRectMake(20, self.height/2 - 30, 60, 60)];
    [active setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleGray];
    [self addSubview:active];
    [active startAnimating];
    
    UILabel *label = [[UILabel alloc] init];
    label.text = SN_Text(@"正在获取固件版本信息...");
    label.textColor = [UIColor blackColor];
    label.textAlignment = NSTextAlignmentCenter;
    label.frame = CGRectMake(20 + 40 +20, self.height/2 -10, self.width - 100, 20);
    label.font = SNSFONT(18.0);
    [self addSubview:label];
}

- (void)showViewProgress:(NSString *)tip
{
    UILabel *label = [[UILabel alloc] init];
    label.text = tip;
    label.textColor = [UIColor blackColor];
    label.textAlignment = NSTextAlignmentLeft;
    label.frame = CGRectMake(20,10,self.frame.size.width - 40, 20);
    label.font = SNSFONT(18.0);
    [self addSubview:label];
    
    UIView *line = [[UIView alloc] init];
    line.frame = SNFRAME(10, label.origin.y + 25, self.width - 20, 1);
    line.backgroundColor = SNCOLORGRAYLINE;
    [self addSubview:line];
    
    _progressView = [[UIProgressView alloc] init];
    _progressView.frame = SNFRAME(20, self.height/2 , self.width - 40, 20);
    _progressView.progress = 0.0;
    _progressView.layer.cornerRadius = 5.0;
    _progressView.layer.masksToBounds = YES;
    _progressView.transform = CGAffineTransformMakeScale(1.0f,5.0f);
    _progressView.progressTintColor = [UIColor blackColor];  // 已走过的颜色
    _progressView.trackTintColor = [UIColor grayColor];      // 背景的颜色
    [self addSubview:_progressView];
    
    _progressLabel = [[UILabel alloc] init];
    _progressLabel.text = @"0%";
    _progressLabel.textColor = [UIColor blackColor];
    _progressLabel.textAlignment = NSTextAlignmentCenter;
    _progressLabel.frame = CGRectMake(self.width - 100,_progressView.origin.y +20,90, 20);
    _progressLabel.font = SNSFONT(18.0);
    [self addSubview:_progressLabel];
    
    self.layer.borderWidth = 1.0;
    self.layer.borderColor = [UIColor blackColor].CGColor;
}

@end
